#include "../inc/show_online.h"

// 显示在线客户端
char *Show_Online_Client(PSI server_info)
{
    PCN client_head = server_info->cli_node_head;
    char *tmp_ip = (char *)malloc(MSG_MAX_LEN * sizeof(char));
    if (tmp_ip == NULL)
    {
        perror("分配内存失败！\n");
        return NULL;
    }

    memset(tmp_ip, 0, MSG_MAX_LEN * sizeof(char));
    // 上锁
    pthread_mutex_lock(&(server_info->mutex));

    for (PCN tmp_client_node = client_head->next;
         tmp_client_node != client_head;
         tmp_client_node = tmp_client_node->next)
    {

        // 把ip地址存入字符串换行符分割
        strcat(tmp_ip, tmp_client_node->cli_ip);
        strcat(tmp_ip, "\n");
    }
    // 解锁
    pthread_mutex_unlock(&(server_info->mutex));

    return tmp_ip;
}

// 显示在线客户端
bool Show_Online_Client_UI(char *str)
{
    printf("💠💠💠💠💠💠💠💠💠💠💠💠在线客户💠💠💠💠💠💠💠💠💠💠💠💠\n");
    printf("%s", str);
    printf("💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠💠\n");

    return true;
}